<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.que_title" placeholder="请输入报价书标题" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button v-if="isAuth('purchase:quote:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <el-button v-if="isAuth('purchase:quote:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>

      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="序号:">
              <span>{{ props.row.id }}</span>
            </el-form-item>
  <br>
            <el-form-item label="报价书编号:">
              <span>{{ props.row.quoteNum }}</span>
            </el-form-item>
  <br>
            <el-form-item label="询价书序号:">
              <span>{{ props.row.enquireId }}</span>
            </el-form-item>
  <br>
            <el-form-item label="供应商序号:">
              <span>{{ props.row.supplierId }}</span>
            </el-form-item>
  <br>
            <el-form-item label="报价单位:">
              <span>{{ props.row.quoCompany }}</span>
            </el-form-item>
  <br>
            <el-form-item label="报价单位地址:">
              <span>{{ props.row.quoAddress }}</span>
            </el-form-item>
<!--  <br>-->
<!--            <el-form-item label="报价单位联系人:">-->
<!--              <span>{{ props.row.quoLinkman }}</span>-->
<!--            </el-form-item>-->
<!--  <br>-->
<!--            <el-form-item label="报价单位电话:">-->
<!--              <span>{{ props.row.quoPhone }}</span>-->
<!--            </el-form-item>-->
<!--  <br>-->
<!--            <el-form-item label="报价单位传真:">-->
<!--              <span>{{ props.row.quoFax }}</span>-->
<!--            </el-form-item>-->
<!--  <br>-->
<!--            <el-form-item label="报价单位电子邮件:">-->
<!--              <span>{{ props.row.quoEmail }}</span>-->
<!--            </el-form-item>-->
  <br>
            <el-form-item label="报价书标题:">
              <span>{{ props.row.queTitle }}</span>
            </el-form-item>
  <br>
            <el-form-item label="报价时间:">
              <span>{{ props.row.queDate }}</span>
            </el-form-item>
  <br>
            <el-form-item label="询价截止时间:">
              <span>{{ props.row.endDate }}</span>
            </el-form-item>
  <br>
            <el-form-item label="数量合计:">
              <span>{{ props.row.sumAmount }}</span>
            </el-form-item>
  <br>
            <el-form-item label="总金额(元):">
              <span>{{ props.row.overallPrice }}</span>
            </el-form-item>
  <br>
            <el-form-item label="报价说明:">
              <span>{{ props.row.quoRemark }}</span>
            </el-form-item>
<!--  <br>
            <el-form-item label="状态:">
              <span>{{ props.row.status }}</span>
            </el-form-item>
  <br>-->
          </el-form>
        </template>
      </el-table-column>

      <el-table-column
        prop="id"
        header-align="center"
        align="center"
        label="序号">
      </el-table-column>
<!--      <el-table-column
        prop="quoteNum"
        header-align="center"
        align="center"
        label="报价书编号">
      </el-table-column>-->
      <el-table-column
        prop="enquireId"
        header-align="center"
        align="center"
        label="询价书序号">
      </el-table-column>
<!--      <el-table-column
        prop="supplierId"
        header-align="center"
        align="center"
        label="供应商序号">
      </el-table-column>
      <el-table-column
        prop="quoCompany"
        header-align="center"
        align="center"
        label="报价单位">
      </el-table-column>
      <el-table-column
        prop="quoAddress"
        header-align="center"
        align="center"
        label="报价单位地址">
      </el-table-column>
      <el-table-column
        prop="quoLinkman"
        header-align="center"
        align="center"
        label="报价单位联系人">
      </el-table-column>
      <el-table-column
        prop="quoPhone"
        header-align="center"
        align="center"
        label="报价单位电话">
      </el-table-column>
      <el-table-column
        prop="quoFax"
        header-align="center"
        align="center"
        label="报价单位传真">
      </el-table-column>
      <el-table-column
        prop="quoEmail"
        header-align="center"
        align="center"
        label="报价单位电子邮件">
      </el-table-column>-->
      <el-table-column
        prop="queTitle"
        header-align="center"
        align="center"
        label="报价书标题">
      </el-table-column>
      <el-table-column
        prop="queDate"
        header-align="center"
        align="center"
        label="报价时间">
      </el-table-column>
      <el-table-column
        prop="endDate"
        header-align="center"
        align="center"
        label="询价截止时间">
      </el-table-column>
<!--      <el-table-column
        prop="sumAmount"
        header-align="center"
        align="center"
        label="数量合计">
      </el-table-column>
      <el-table-column
        prop="overallPrice"
        header-align="center"
        align="center"
        label="总金额(元)">
      </el-table-column>
      <el-table-column
        prop="quoRemark"
        header-align="center"
        align="center"
        label="报价说明">
      </el-table-column>
      <el-table-column
        prop="status"
        header-align="center"
        align="center"
        label="状态">
      </el-table-column>-->
      <el-table-column
        prop="dictEntity.desc"
        header-align="center"
        align="center"
        label="采购类型">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
<!--          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>-->
          <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
          <el-button type="text" size="small" @click="selectDetails(scope.row.id)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './quote-add-or-update'
  export default {
    data () {
      return {
        dataForm: {
          que_title: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
         addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate
    },
    mounted () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/purchase/quote/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'que_title': this.dataForm.que_title
          })
        }).then((data) => {
          if (data && data.code === 200) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/purchase/quote/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 200) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      selectDetails(id){
        console.log(id)
        this.$router.push({name : 'details' , query: {id: id}})
        // this.$http({
        //   url: this.$http.adornUrl(`/purchase/quote/info/${id}`),
        //   method: 'get',
        // }).then((data) => {
        //   console.log(data)
        //   if (data && data.code === 200) {
        //     this.dataList = data.page.list
        //     this.totalPage = data.page.totalCount
        //     console.log(data)
        //   } else {
        //     this.dataList = []
        //     this.totalPage = 0
        //   }
        // })
      }
    }
  }
</script>
